package avicit.bdp.dcs.job.dto;

import avicit.bdp.common.base.BaseDTO;
import avicit.bdp.common.dto.api.APIHttpDefinition;
import avicit.bdp.dcs.semistructure.dto.HiveJsonDto;
import avicit.bdp.dcs.stream.dto.KafkaJsonDto;
import avicit.bdp.dcs.task.dto.TaskDTO;
import avicit.platform6.core.annotation.log.FieldRemark;
import avicit.platform6.core.annotation.log.Id;
import avicit.platform6.core.annotation.log.LogField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-08-04 11:32
 * @类说明：数据迁移同步实体类
 * @修改记录：
 */
@ApiModel(value = "JobDTO", description = "bdp_dcs_job")
@Table(name = "bdp_dcs_job")
public class JobDTO extends BaseDTO {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Id
    @LogField
    @ApiModelProperty(value = "主键")
    @FieldRemark(column = "id", field = "id", name = "id")
    @javax.persistence.Id
    @Column(name = "id")
    private String id;

    /**
     * 数据项目Id
     */
    @LogField
    @ApiModelProperty(value = "数据项目Id")
    @FieldRemark(column = "project_id", field = "projectId", name = "数据项目Id")
    @Column(name = "project_id")
    private String projectId;

    /**
     * 作业名称
     */
    @LogField
    @ApiModelProperty(value = "作业名称")
    @FieldRemark(column = "name", field = "name", name = "作业名称")
    @Column(name = "name")
    //@Length(min = 1, max = 30, message = "作业名称长度限制[1-30]")
    private String name;

    /**
     * 类型:
     * 数据迁移：1
     * 数据同步：2
     * 半结构化采集：3
     * 流式采集：5
     * API Http采集: 6
     * @see avicit.bdp.common.utils.enums.JobType
     */
    @LogField
    @ApiModelProperty(value = "类型[数据迁移：1，数据同步：2，半结构化采集：3，流式采集：5, API: 6]")
    @FieldRemark(column = "job_type", field = "jobType", name = "类型")
    @Column(name = "job_type")
    private Integer jobType;

    /**
     * 源数据源
     */
    @LogField
    @ApiModelProperty(value = "源数据源")
    @FieldRemark(column = "src_datasource_id", field = "srcDatasourceId", name = "源数据源")
    @Column(name = "src_datasource_id")
    private String srcDatasourceId;

    /**
     * 目标数据源
     */
    @LogField
    @ApiModelProperty(value = "目标数据源")
    @FieldRemark(column = "dst_datasource_id", field = "dstDatasourceId", name = "目标数据源")
    @Column(name = "dst_datasource_id")
    private String dstDatasourceId;

    /**
     * 源库名
     */
    @LogField
    @ApiModelProperty(value = "源库名")
    @FieldRemark(column = "src_schema_name", field = "srcSchemaName", name = "源库名")
    @Column(name = "src_schema_name")
    private String srcSchemaName;

    /**
     * 目标库名
     */
    @LogField
    @ApiModelProperty(value = "目标库名")
    @FieldRemark(column = "dst_schema_name", field = "dstSchemaName", name = "目标库名")
    @Column(name = "dst_schema_name")
    private String dstSchemaName;

    /**
     * 迁移类型，
     * 表结构迁移：1
     * 数据迁移：2
     * 两者都有：1,2
     */
    @LogField
    @ApiModelProperty(value = "迁移类型，表结构迁移：1，数据迁移：2，两者都有：1,2")
    @FieldRemark(column = "transfer_type", field = "transferType", name = "迁移类型")
    @Column(name = "transfer_type")
    private String transferType;

    /**
     * 同步初始化：否：0，是：1
     */
    @LogField
    @ApiModelProperty(value = "同步初始化：否：0，是：1")
    @FieldRemark(column = "table_init", field = "tableInit", name = "同步初始化")
    @Column(name = "table_init")
    private Integer tableInit;

    /**
     * 目标已存在表的处理模式，预检查并报错拦截：0，覆盖目标表：1，保留目标表：2
     */
    @ApiModelProperty(value = "目标已存在表的处理模式，预检查并报错拦截：0，覆盖目标表：1，保留目标表：2")
    @FieldRemark(column = "process_mode", field = "processMode", name = "目标已存在表的处理模式")
    @Column(name = "process_mode")
    private Integer processMode;

    /**
     * 待迁移、同步表 [{"src_table":"order","dst_table":"neworder"},{"src_table":"customer","dst_table":"test_customer"}]
     */
    @LogField
    @ApiModelProperty(value = "待迁移、同步表 [{\"src_table\":\"order\",\"dst_table\":\"neworder\"}]")
    @FieldRemark(column = "selected_table", field = "selectedTable", name = "待迁移、同步表")
    @Column(name = "selected_table")
    private String selectedTable;

    /**
     * 状态，草稿：20，预检中：21，预检失败：22，未启动：23，同步中：1，同步失败：6，暂停中：3，完成：7
     */
    @LogField
    @ApiModelProperty(value = "状态，草稿：20，预检中：21，预检失败：22，未启动：23，同步中：1，同步失败：6，暂停中：3，完成：7")
    @FieldRemark(column = "job_status", field = "jobStatus", name = "状态")
    @Column(name = "job_status")
    private Integer jobStatus;

    /**
     * 是否启用，停用：0，启用：1
     */
    @LogField
    @ApiModelProperty(value = "是否启用，停用：0，启用：1")
    @FieldRemark(column = "enable", field = "enable", name = "是否启用")
    @Column(name = "enable")
    private Integer enable;

    /**
     * 平均迁移速度
     */
    @ApiModelProperty(value = "平均迁移速度")
    @FieldRemark(column = "task_avg_speed", field = "taskAvgSpeed", name = "平均迁移速度")
    @Column(name = "task_avg_speed")
    private Long taskAvgSpeed;

    /**
     * 记录平均写入速度
     */
    @ApiModelProperty(value = "记录平均写入速度")
    @FieldRemark(column = "task_write_speed", field = "taskWriteSpeed", name = "记录平均写入速度")
    @Column(name = "task_write_speed")
    private Long taskWriteSpeed;

    /**
     * 迁移数据大小
     */
    @ApiModelProperty(value = "迁移数据大小")
    @FieldRemark(column = "read_succeed_bytes", field = "readSucceedBytes", name = "迁移数据大小")
    @Column(name = "read_succeed_bytes")
    private Long readSucceedBytes;

    /**
     * 是否删除，否：0，是：1
     */
    @LogField
    @ApiModelProperty(value = "是否删除，否：0，是：1")
    @FieldRemark(column = "flag", field = "flag", name = "是否删除")
    @Column(name = "flag")
    private Integer flag;

    /**
     * 同步间隔(秒)
     */
    @LogField
    @ApiModelProperty(value = "同步间隔(秒)")
    @FieldRemark(column = "sync_interval", field = "syncInterval", name = "同步间隔(秒)")
    @Column(name = "sync_interval")
    private Integer syncInterval;

    /**
     * ds流程定义id
     */
    @LogField
    @ApiModelProperty(value = "ds流程定义id")
    @FieldRemark(column = "process_definition_id", field = "processDefinitionId", name = "ds流程定义id")
    @Column(name = "process_definition_id")
    private String processDefinitionId;

    /**
     * 配置定时任务，是：1，否：0
     */
    @LogField
    @ApiModelProperty(value = "配置定时任务，是：1，否：0")
    @FieldRemark(column = "config_crontab", field = "configCronTab", name = "配置定时任务，是：1，否：0")
    @Column(name = "config_crontab")
    private Integer configCronTab;

    /**
     * 启用定时任务，是：1，否：0
     */
    @LogField
    @ApiModelProperty(value = "启用定时任务，是：1，否：0")
    @FieldRemark(column = "enable_crontab", field = "enableCronTab", name = "启用定时任务，是：1，否：0")
    @Column(name = "enable_crontab")
    private Integer enableCronTab;

    /**
     * 半结构化采集：待同步目录，目录路径；流式采集：已选择消息模板，逗号分隔
     */
    @LogField
    @ApiModelProperty(value = "待同步目录")
    @FieldRemark(column = "selected_file", field = "selectedFile", name = "待同步目录")
    @Column(name = "selected_file")
    private String selectedFile;

    /**
     * 附加参数
     */
    @LogField
    @ApiModelProperty(value = "附加参数")
    @FieldRemark(column = "extra_params", field = "extraParams", name = "附加参数")
    @Column(name = "extra_params")
    private String extraParams;

    /**
     * kafka配置json数据
     * {"topics":"kafka2hive","msgId":"1fdcv54rgh","msgAgreement":"json","msgTemplate":"airplane","kafkaPartitions":"1",
     * "defaultFS":"hdfs://192.168.0.28:8020","analysisMode":""}
     * topics:：kafka主题
     * msgId：消息唯一标识
     * msgAgreement：消息协议：json,xml,avro,protobuf
     * msgTemplate：消息模板标识
     * kafkaPartitions：kafka分区
     * defaultFS：defaultFS
     * analysisMode：解析方式
     */
    @ApiModelProperty(value = "kafka配置json数据")
    @FieldRemark(column = "kafka_json", field = "kafkaJson", name = "kafka配置json数据")
    @Column(name = "kafka_json")
    private String kafkaJson;

    /**
     * 同步方式
     * 全量同步：1
     * 增量同步：0
     */
    @LogField
    @ApiModelProperty(value = "同步方式，全量同步：1，增量同步：0")
    @FieldRemark(column = "sync_mode", field = "syncMode", name = "同步方式")
    @Column(name = "sync_mode")
    private Integer syncMode;

    /**
     * 平均迁移速度(带单位)
     */
    @ApiModelProperty(value = "平均迁移速度(带单位)")
    @Transient
    private String taskAvgSpeedUnit;

    /**
     * 迁移数据大小(带单位)
     */
    @ApiModelProperty(value = "迁移数据大小(带单位)")
    @Transient
    private String readSucceedBytesUnit;

    /**
     * 创建表进度
     */
    @ApiModelProperty(value = "创建表进度")
    @Transient
    private String createTableProgress;

    /**
     * kafka配置json数据实体类
     */
    @ApiModelProperty(value = "kafka配置json数据")
    @Transient
    private KafkaJsonDto kafkaJsonDto;

    /**
     * 迁移数据进度
     */
    @ApiModelProperty(value = "迁移数据进度")
    @Transient
    private String dataCollectProgress;

    /**
     * 目标数据库类型
     */
    @ApiModelProperty(value = "目标数据库类型")
    @Transient
    private String dstDbType;

    @ApiModelProperty(value = "taskDTO")
    @Transient
    private TaskDTO taskDTO;

    @ApiModelProperty(value = "hiveJsonDto")
    @Transient
    private HiveJsonDto hiveJsonDto;

    @ApiModelProperty(value = "processInstanceId")
    @Transient
    private String processInstanceId;

    /**
     * API采集任务配置
     */
    @ApiModelProperty(value = "apiHttpDefinition")
    @Transient
    private APIHttpDefinition apiHttpDefinition;

    public APIHttpDefinition getApiHttpDefinition() {
        return apiHttpDefinition;
    }

    public void setApiHttpDefinition(APIHttpDefinition apiHttpDefinition) {
        this.apiHttpDefinition = apiHttpDefinition;
    }

    public String getId() {
        return id;
    }

    public String getKafkaJson() {
        return kafkaJson;
    }

    public void setKafkaJson(String kafkaJson) {
        this.kafkaJson = kafkaJson;
    }

    public KafkaJsonDto getKafkaJsonDto() {
        return kafkaJsonDto;
    }

    public void setKafkaJsonDto(KafkaJsonDto kafkaJsonDto) {
        this.kafkaJsonDto = kafkaJsonDto;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getJobType() {
        return jobType;
    }

    public void setJobType(Integer jobType) {
        this.jobType = jobType;
    }

    public String getSrcDatasourceId() {
        return srcDatasourceId;
    }

    public void setSrcDatasourceId(String srcDatasourceId) {
        this.srcDatasourceId = srcDatasourceId;
    }

    public String getDstDatasourceId() {
        return dstDatasourceId;
    }

    public void setDstDatasourceId(String dstDatasourceId) {
        this.dstDatasourceId = dstDatasourceId;
    }

    public String getSrcSchemaName() {
        return srcSchemaName;
    }

    public void setSrcSchemaName(String srcSchemaName) {
        this.srcSchemaName = srcSchemaName;
    }

    public String getDstSchemaName() {
        return dstSchemaName;
    }

    public void setDstSchemaName(String dstSchemaName) {
        this.dstSchemaName = dstSchemaName;
    }

    public String getTransferType() {
        return transferType;
    }

    public void setTransferType(String transferType) {
        this.transferType = transferType;
    }

    public void setTableInit(Integer tableInit) {
        this.tableInit = tableInit;
    }

    public Integer getTableInit() {
        return tableInit;
    }

    public Integer getProcessMode() {
        return processMode;
    }

    public void setProcessMode(Integer processMode) {
        this.processMode = processMode;
    }

    public String getSelectedTable() {
        return selectedTable;
    }

    public void setSelectedTable(String selectedTable) {
        this.selectedTable = selectedTable;
    }

    public Integer getJobStatus() {
        return jobStatus;
    }

    public void setJobStatus(Integer jobStatus) {
        this.jobStatus = jobStatus;
    }

    public Integer getEnable() {
        return enable;
    }

    public void setEnable(Integer enable) {
        this.enable = enable;
    }

    public Long getTaskAvgSpeed() {
        return taskAvgSpeed;
    }

    public void setTaskAvgSpeed(Long taskAvgSpeed) {
        this.taskAvgSpeed = taskAvgSpeed;
    }

    public Long getTaskWriteSpeed() {
        return taskWriteSpeed;
    }

    public void setTaskWriteSpeed(Long taskWriteSpeed) {
        this.taskWriteSpeed = taskWriteSpeed;
    }

    public Long getReadSucceedBytes() {
        return readSucceedBytes;
    }

    public void setReadSucceedBytes(Long readSucceedBytes) {
        this.readSucceedBytes = readSucceedBytes;
    }

    public Integer getFlag() {
        return flag;
    }

    public void setFlag(Integer flag) {
        this.flag = flag;
    }

    public String getProcessDefinitionId() {
        return processDefinitionId;
    }

    public void setProcessDefinitionId(String processDefinitionId) {
        this.processDefinitionId = processDefinitionId;
    }

    public String getCreateTableProgress() {
        return createTableProgress;
    }

    public void setCreateTableProgress(String createTableProgress) {
        this.createTableProgress = createTableProgress;
    }

    public String getDataCollectProgress() {
        return dataCollectProgress;
    }

    public void setDataCollectProgress(String dataCollectProgress) {
        this.dataCollectProgress = dataCollectProgress;
    }

    public Integer getSyncInterval() {
        return syncInterval;
    }

    public void setSyncInterval(Integer syncInterval) {
        this.syncInterval = syncInterval;
    }

    public String getTaskAvgSpeedUnit() {
        return taskAvgSpeedUnit;
    }

    public void setTaskAvgSpeedUnit(String taskAvgSpeedUnit) {
        this.taskAvgSpeedUnit = taskAvgSpeedUnit;
    }

    public String getReadSucceedBytesUnit() {
        return readSucceedBytesUnit;
    }

    public void setReadSucceedBytesUnit(String readSucceedBytesUnit) {
        this.readSucceedBytesUnit = readSucceedBytesUnit;
    }

    public Integer getConfigCronTab() {
        return configCronTab;
    }

    public void setConfigCronTab(Integer configCronTab) {
        this.configCronTab = configCronTab;
    }

    public Integer getEnableCronTab() {
        return enableCronTab;
    }

    public void setEnableCronTab(Integer enableCronTab) {
        this.enableCronTab = enableCronTab;
    }

    public String getSelectedFile() {
        return selectedFile;
    }

    public void setSelectedFile(String selectedFile) {
        this.selectedFile = selectedFile;
    }

    public String getExtraParams() {
        return extraParams;
    }

    public void setExtraParams(String extraParams) {
        this.extraParams = extraParams;
    }

    public String getDstDbType() {
        return dstDbType;
    }

    public void setDstDbType(String dstDbType) {
        this.dstDbType = dstDbType;
    }

    public TaskDTO getTaskDTO() {
        return taskDTO;
    }

    public void setTaskDTO(TaskDTO taskDTO) {
        this.taskDTO = taskDTO;
    }

    public HiveJsonDto getHiveJsonDto() {
        return hiveJsonDto;
    }

    public void setHiveJsonDto(HiveJsonDto hiveJsonDto) {
        this.hiveJsonDto = hiveJsonDto;
    }

    public String getProcessInstanceId() {
        return processInstanceId;
    }

    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }

    public Integer getSyncMode() {
        return syncMode;
    }

    public void setSyncMode(Integer syncMode) {
        this.syncMode = syncMode;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    @Override
    public String getLogFormName() {
        if (StringUtils.isEmpty(super.logFormName)) {
            return "作业管理";
        } else {
            return super.logFormName;
        }
    }

    @Override
    public String getLogTitle() {
        if (StringUtils.isEmpty(super.logTitle)) {
            return "作业";
        } else {
            return super.logTitle;
        }
    }

}
